package com.soft.javase.day13;


import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/5/22
 */
public class LinkedBlockingQueueDemo {
    LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();

    public void add(Runnable runnable) {
        try {
            queue.put(runnable);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void take(){
            while(true){
                try {
                    queue.take().run();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
    }

    public static void main(String[] args) {
        LinkedBlockingQueueDemo queueDemo = new LinkedBlockingQueueDemo();
        new Thread(queueDemo::take).start();
        queueDemo.add(()-> System.out.println("C"));
        queueDemo.add(()-> System.out.println("B"));
        queueDemo.add(()-> System.out.println("A"));
    }
}
